﻿@using Newtouch.Infrastructure;
@{

    ViewBag.Title = "编辑摄入量";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<!DOCTYPE html>

<form id="form1">
    <div style="padding: 20px 20px 0 2px;">
        <table class="form" id="tabletime">
            <tr>
                <th class="formTitle">住院号：</th>
                <td><label id="zyh"></label></td>
                <th class="formTitle">姓名：</th>
                <td><label id="xm"></label></td>
                <th class="formTitle">时间：</th>
                <td colspan="2"><label id="rqsj"></label></td>
            </tr>
            <tr>
                <th class="formTitle">摄入量录入：</th>
                <td>
                    <i id="zdCircle" class="fa fa-plus-circle plusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;" onclick="btn_addtime()"></i>
                </td>
                <th class="formTitle"></th>
                <td></td>
                <th class="formTitle"></th>
                <td></td>
                <th class="formTitle"></th>
                <td></td>
            </tr>
            <tr id="rcl1">
                <th class="formTitle">名称 ：</th>
                <td class="formValue">
                    <input id="mc1" type="text" class="form-control" />
                </td>
                <th class="formTitle">量 ：</th>
                <td class="formValue">
                    <input id="ml1" type="text" class="form-control" />
                </td>
                <th class="formTitle">单位 ：</th>
                <td class="formValue">
                    <input id="dw1" type="text" class="form-control" />
                </td>
                <th class="formTitle">途径 ：</th>
                <td class="formValue">
                    <input id="tj1" type="text" class="form-control" />
                </td>
            </tr>
        </table>
        </div>
</form>

<script>
    var zyh = $.request("zyh");
    var xm = $.request("xm");
    var rq = $.request("rq");
    var sj = $.request("sj");
    var bllx = $.request("bllx"); 
    var srlstr = $.request("srscl");
    var inttime = 2;
    $(function () {
        $('#zyh').text(zyh);
        $('#xm').text(xm);
        $('#rqsj').text(rq + " " + sj);
        if (srlstr!="") {
            for (var i = 0; i < srlstr.split(",").length; i++) {
                if (i == 0) {
                    $('#mc1').val(srlstr.split(",")[i].split("|")[0]);
                    $('#ml1').val(srlstr.split(",")[i].split("|")[1]);
                    $('#dw1').val(srlstr.split(",")[i].split("|")[2]);
                    $('#tj1').val(srlstr.split(",")[i].split("|")[3]);
                } else {
                    var thisHtml = '<tr id="rcl' + inttime + '"><th class="formTitle"><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"  onclick="btn_clertime(' + inttime + ')"></i>名称 ：</th><td class="formValue"><input id="mc' + inttime + '" type="text" value="' + srlstr.split(",")[i].split("|")[0] + '" class="form-control" /></td><th class="formTitle">量 ：</th><td class="formValue"><input id="ml' + inttime + '" type="text"  value="' + srlstr.split(",")[i].split("|")[1] + '" class="form-control" /></td><th class="formTitle">单位 ：</th><td class="formValue"><input id="dw' + inttime + '" type="text"  value="' + srlstr.split(",")[i].split("|")[2] + '" class="form-control" /></td><th class="formTitle">途径 ：</th><td class="formValue"><input id="tj' + inttime + '" type="text" class="form-control" value="' + srlstr.split(",")[i].split("|")[3] + '" /></td></tr>'
                    $('#tabletime').append(thisHtml);
                    inttime += 1;
                }
            }
        }
    });
    function btn_addtime() {
        var thisHtml = '<tr id="rcl' + inttime + '"><th class="formTitle"><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"  onclick="btn_clertime(' + inttime + ')"></i>名称 ：</th><td class="formValue"><input id="mc' + inttime + '" type="text" class="form-control" /></td><th class="formTitle">量 ：</th><td class="formValue"><input id="ml' + inttime + '" type="text" class="form-control" /></td><th class="formTitle">单位 ：</th><td class="formValue"><input id="dw' + inttime + '" type="text" class="form-control" /></td><th class="formTitle">途径 ：</th><td class="formValue"><input id="tj' + inttime + '" type="text" class="form-control" /></td></tr>'
        //var thisHtml = '<tr id="rcl' + inttime + '"><th class="formTitle"><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"  onclick="btn_clertime(' + inttime + ')"></i>开始时间 ：</th><td class="formValue"><input id="begintime' + inttime + '" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("HH:mm")" onfocus="WdatePicker({ dateFmt: \'HH:mm\' })" /></td><th class="formTitle">结束时间 ：</th><td class="formValue"><input id="endtime' + inttime + '" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("HH:mm")" onfocus="WdatePicker({ dateFmt: \'HH:mm\' })" /></td></tr>';
        $('#tabletime').append(thisHtml);
        inttime += 1;
    }
    function btn_clertime(inttimetr) {
        $('#rcl' + inttimetr).html('');
    }
    function AcceptClick(callBack) {
        var srlstr = "";
        for (var i = 1; i < inttime; i++) {
            if ($('#mc' + i).val() != undefined && $('#mc' + i).val() != "") {
                srlstr += $('#mc' + i).val() + "|" + $('#ml' + i).val() + "|" + $('#dw' + i).val() + "|" + $('#tj' + i).val() + ",";
            }
        }
        srlstr = srlstr.substring(0, srlstr.length - 1);
        callBack(srlstr);
        $.modalClose();
    }
</script>
